#ifndef AREA_NAVIGATOR_HPP
#define AREA_NAVIGATOR_HPP

#include <ros/ros.h>
#include <actionlib/client/simple_action_client.h>
#include <move_base_msgs/MoveBaseAction.h>
#include <geometry_msgs/PoseStamped.h>
#include <geometry_msgs/PoseWithCovarianceStamped.h>
#include <tf/transform_listener.h>
#include <std_srvs/Trigger.h>
#include <visualization_msgs/Marker.h>

class AreaNavigator
{
public:
    AreaNavigator();
    virtual ~AreaNavigator() = default;

private:
    // 类型定义
    using MoveBaseClient = actionlib::SimpleActionClient<move_base_msgs::MoveBaseAction>;
    
    // ROS组件
    ros::NodeHandle nh_;
    std::unique_ptr<MoveBaseClient> move_base_client_;
    ros::Subscriber goal_sub_;
    ros::Subscriber pose_sub_;
    ros::Publisher marker_pub_;
    ros::ServiceServer reset_service_;
    
    tf::TransformListener tf_listener_;
    
    // 定时器
    ros::Timer monitor_timer_;
    ros::Timer marker_timer_;
    // 参数结构
    struct TargetArea {
        geometry_msgs::Point center;
        double radius;
        double adjust_yaw_tolerance;
        geometry_msgs::Pose target_pose;
        bool active;
    };
    
    // 成员变量
    TargetArea target_area; 
    move_base_msgs::MoveBaseActionGoal current_goal_;
    geometry_msgs::PoseStamped current_pose_;
    bool has_active_goal_;
    bool is_in_adjustment_;
    std::string current_area_id_;
    
        // 方法
    void loadParameters();
    void initializeROSComponents();
    void goalPoseCallback(const move_base_msgs::MoveBaseActionGoal::ConstPtr& msg);
    void robotPoseCallback(const geometry_msgs::PoseStamped::ConstPtr& msg);
    void monitorNavigation(const ros::TimerEvent& event);
    bool isInTargetArea(const geometry_msgs::PoseStamped& pose, TargetArea& area);
    void adjustPoseInArea(const TargetArea& area);
    void resumeNavigation();
    void publishVisualizationMarkers();  
     // 动作回调
    void goalActiveCallback();
    void goalFeedbackCallback(const move_base_msgs::MoveBaseFeedbackConstPtr& feedback);
    void goalDoneCallback(const actionlib::SimpleClientGoalState& state,
                         const move_base_msgs::MoveBaseResultConstPtr& result);
    
    // 服务回调
    bool resetServiceCallback(std_srvs::Trigger::Request& req,
                             std_srvs::Trigger::Response& res);


};

#endif // AREA_NAVIGATOR_HPP